using System;
using System.Globalization;
#if NETFX_CORE
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
#else
using System.Windows.Data;
#endif

namespace FreshMeat.Xaml
{
#if !SILVERLIGHT && !NETFX_CORE
   [System.Windows.Markup.MarkupExtensionReturnType(typeof(IValueConverter))]
#endif
#if NETFX_CORE
   public class ObjectToBoolExtension : IValueConverter
   {
#else
   public class ObjectToBoolExtension : System.Windows.Markup.MarkupExtension, IValueConverter
   {
      static ObjectToBoolExtension converter;

      public override object ProvideValue(IServiceProvider serviceProvider)
      {
         return converter ?? (converter = new ObjectToBoolExtension());
      }
#endif

#if NETFX_CORE
      public object Convert(object value, Type targetType, object parameter, string culture)
#else
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
#endif
      {
         return value != null;
      }

#if NETFX_CORE
      public object ConvertBack(object value, Type targetType, object parameter, string culture)
#else
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
#endif
      {
         throw new InvalidOperationException("Cannot convert from bool back to object.");
      }
   }
}